<?php

	/* This class will hold all our SQLite Database-related functions! :) */
	class Database
	{
		/* This will store our database connection */
		private $dbhandle;
		
		/* This function connects to the Database */
		private function connect()
		{
			/* We need the global configuration */
			global $DBconf;
			
			/* Connect to the database and save the resource in the var */
			$this->dbhandle = new SQLiteDatabase($DBconf["file"]);
		}
		
		/* Close our database connection */
		private function disconnect()
		{
			/* Close it right away :) */
			unset($this->dbhandle);     # sqlite_close($this->dbhandle);
		}
		
		/* Executes a SQL-Statement */
		public function exec($sql)
		{
			/* Execute our query */
			$this->dbhandle->query($sql);
		}
		
		/* Queries the database */
		public function query($sql) {
			/* Execute our query and save the results */
			$result = $this->dbhandle->arrayQuery($sql);
			
			/* Detect if the results have errors and return them to the user if not */
			if (result == false ) {
				print "Error";
			}
			else {
				return $result;
			}
		}
		
		/* Constructor for our class */
		public function __construct() {
			/*
			 * Connect to the Database
			 */
			$this->connect();
		}
		
		/* Destructor for our class */
		public function __destruct() {
			/* Close the connection to the database */ 
			$this->disconnect();
		}
	}
?>